//
//  MSPhotoBrowser.h
//  LDIMPhotoBrowser
//
//  Created by zzg on 2021/8/30.
//

#import <UIKit/UIKit.h>
#import "MSPhoto.h"
#import "MSPhotoProtocol.h"
#import "MSCaptionView.h"
#import "MSImageAndVideoScrollView.h"

// Debug Logging
#if 0 // Set to 1 to enable debug logging
#define MSMWLog(x, ...) NSLog(x, ## __VA_ARGS__);
#else
#define MSMWLog(x, ...)
#endif

@class MSPhotoBrowser;

@protocol MSPhotoBrowserDelegate <NSObject>

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MSPhotoBrowser *)photoBrowser;
- (id <MSPhoto>)photoBrowser:(MSPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index;

@optional
- (id <MSPhoto>)photoBrowser:(MSPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index;
- (MSCaptionView *)photoBrowser:(MSPhotoBrowser *)photoBrowser captionViewForPhotoAtIndex:(NSUInteger)index;
- (NSString *)photoBrowser:(MSPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index;
- (void)photoBrowser:(MSPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index;
- (void)photoBrowser:(MSPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index;
- (BOOL)photoBrowser:(MSPhotoBrowser *)photoBrowser isPhotoSelectedAtIndex:(NSUInteger)index;
- (void)photoBrowser:(MSPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index selectedChanged:(BOOL)selected;
- (void)photoBrowser:(MSPhotoBrowser *)photoBrowser finishedDownloadImageWithIndex:(NSUInteger)index originUrl:(NSString *)url isOrigin:(BOOL)isOrigin imageData:(NSData *)imageData;
- (void)photoBrowser:(MSPhotoBrowser *)photoBrowser downloadImageWithIndex:(NSUInteger)index;

- (void)photoBrowserDidFinishModalPresentation:(MSPhotoBrowser *)photoBrowser;

- (void)photoBrowerDidLongPressed:(MSPhotoBrowser *)photoBrowser;

//  视频已经播放的回调 通知业务这个视频已经播放了
- (void)photoBrowser:(MSPhotoBrowser *)photoBrowser didPlayVideo:(NSUInteger)index;
- (void)photoBrowser:(MSPhotoBrowser *)photoBrowser didMoreClicked:(NSUInteger)index;
- (void)photoBrowser:(MSPhotoBrowser *)photoBrowser runLoopCheck:(NSUInteger)index;

@end

@interface MSPhotoBrowser : UIViewController <UIScrollViewDelegate, UIActionSheetDelegate>

@property (nonatomic, weak) IBOutlet id<MSPhotoBrowserDelegate> delegate;
@property (nonatomic) BOOL zoomPhotosToFill;
@property (nonatomic) BOOL displayNavArrows;
@property (nonatomic) BOOL displayActionButton;
@property (nonatomic) BOOL displaySelectionButtons;
@property (nonatomic) BOOL alwaysShowControls;
@property (nonatomic) BOOL enableGrid;
@property (nonatomic) BOOL enableSwipeToDismiss;
@property (nonatomic) BOOL startOnGrid;
@property (nonatomic) BOOL autoPlayOnAppear;
@property (nonatomic) NSUInteger delayToHideElements;
@property (nonatomic, readonly) NSUInteger currentIndex;
@property (nonatomic, strong)  UIView *snapshotView;

// Customise image selection icons as they are the only icons with a colour tint
// Icon should be located in the app's main bundle
@property (nonatomic, strong) NSString *customImageSelectedIconName;
@property (nonatomic, strong) NSString *customImageSelectedSmallIconName;
@property (nonatomic) BOOL showMoreButton;  // need show moreButton, default no

// Views
@property (nonatomic, strong) MSImageAndVideoScrollView *pagingScrollView;

// Init
- (id)initWithPhotos:(NSArray *)photosArray;
- (id)initWithDelegate:(id <MSPhotoBrowserDelegate>)delegate;

// Reloads the photo browser and refetches data
- (void)reloadData;

// Set page that photo browser starts on
- (void)setCurrentPhotoIndex:(NSUInteger)index;

// Navigation
- (void)showNextPhotoAnimated:(BOOL)animated;
- (void)showPreviousPhotoAnimated:(BOOL)animated;

@end
